package com.wkk.controller;

import com.wkk.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    @RequestMapping("/add/{keywords}")
    public boolean add(@PathVariable("keywords")String keywords) throws IOException {
        return contentService.parseContent(keywords);
    }

    /**
     * 前端可以通过Vue+Axios接收
     * 若是高亮的话 则前端通过
     * <a v-html="info.title"></>
     * 替换
     * <a>{{info.title}}</a>
     * @param keywords
     * @param pageNo
     * @param pageSize
     * @return
     * @throws IOException
     */
    @RequestMapping("page/{keywords}/{pageNo}/{pageSize}")
    public List<Map<String,Object>> getPage(
            @PathVariable("keywords")String keywords,
            @PathVariable("pageNo")Integer pageNo,
            @PathVariable("pageSize")Integer pageSize
    ) throws IOException {
        return contentService.searchPage(keywords,pageNo,pageSize);

    }

}
